package com.itheima.reggie.controller;


import com.itheima.reggie.common.R;
import com.itheima.reggie.dao.EchartsDto;
import com.itheima.reggie.mapper.EchartsMapper;
import com.sun.org.apache.xerces.internal.impl.xpath.XPath;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/statics")
public class EchartsController {

    @Autowired
    EchartsMapper echartsMapper;

    @GetMapping("/dishCash")
    public R<EchartsDto> dishCash(){
        List<EchartsDto> dishCategoryCash = echartsMapper.dishCategoryCash();
        EchartsDto echartsDto1 = new EchartsDto();


        ArrayList<Map> objects = new ArrayList<>();


        dishCategoryCash.forEach(echartsDto -> {
            HashMap<String, Object> objectObjectHashMap = new HashMap<>();
            objectObjectHashMap.put("name",echartsDto.getName());
            objectObjectHashMap.put("value",echartsDto.getValue());
            objects.add(objectObjectHashMap);
            });
        echartsDto1.setDishCategoryCash(objects);
        System.out.println(echartsDto1.getDishCategoryCash());
        return R.success(echartsDto1);
    }

}
